home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1992 / number1 / l5.c < prev    next >
Text File  |  1992-01-19  |  975b  |  26 lines

  1. /* Finds the first node in a value-sorted linked list that
  2.    has a Value field greater than or equal to a key value, and
  3.    returns a pointer to the node preceding that node (to facilitate
  4.    insertion and deletion), or a NULL pointer if no such value was
  5.    found. Assumes the list is terminated with a sentinel tail node
  6.    containing the largest possible Value field setting and pointing
  7.    to itself as the next node. */
  8.  
  9. #include <stdio.h>
  10. #include "llist.h"
  11.  
  12. struct LinkNode *FindNodeBeforeValueNotLess(
  13.    struct LinkNode *HeadOfListNode, int SearchValue)
  14. {
  15.    struct LinkNode *NodePtr = HeadOfListNode;
  16.  
  17.    while (NodePtr->NextNode->Value < SearchValue)
  18.       NodePtr = NodePtr->NextNode;
  19.  
  20.    if (NodePtr->NextNode->NextNode == NodePtr->NextNode)
  21.       return(NULL);     /* we found the sentinel; failed search */
  22.    else
  23.       return(NodePtr);  /* success; return pointer to node preceding
  24.                            node that was >= */
  25. }
  26.